<?php
/**
 * Created by PhpStorm.
 * User: andrei
 * Date: Jun 27, 2012
 * Time: 3:28:19 PM
 * To change this template use File | Settings | File Templates.
 */
 
class Db_Products_ProductPages extends Common {
	protected static $tableName = TAB_PRODUCT_PAGES;
	protected static $dbFields = array(
        'id',
		'pp_product_id',
		'pp_template_id',
		'pp_page_index',
        'deleted'
	);

	/**
	 * @var Db_Products_ProductPages
	 */
	public $objectArray;

	public $id;
	public $pp_product_id;
	public $pp_template_id;
	public $pp_page_index;
    public $deleted;

    function __construct($value=NULL, $fieldName=NULL) {
        parent::__construct($value, $fieldName);
    }

	public static function getProductsUsedByTemplateId($templateId) {
		if(!$templateId) {
			return false;
		}
		$sql = "SELECT COUNT(*) FROM ?f
				WHERE `pp_template_id` = ?d AND `deleted` = 0
				GROUP BY `pp_product_id` ;";

		return self::$DB->selectCell($sql, self::$tableName, $templateId);
	}

}